<!-- user表单弹窗 -->
<form id="employee-form" lay-filter="employee-form" class="layui-form model-form">
    <input name="id" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div style="text-align: center">
            <img data-anim="layui-anim-scaleSpring" class="layui-upload layui-anim layui-anim-rotate" id="id_upload_img"
                 src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=3447607612,626410332&fm=26&gp=0.jpg"
                 style="border-radius: 50%; width: 10%;margin:0px 100px 0px 0px;">
        </div>
    </div>
    <div class="layui-form-item" style="width: 300px">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input name="fullName" placeholder="请输入姓名" type="text" class="layui-input" maxlength="20"
                   lay-verify="required" required/>
        </div>
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="0" title="男" checked/>
            <input type="radio" name="sex" value="1" title="女" checked/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">联系方式</label>
        <div class="layui-input-block" style="width: 300px">
            <input name="phone" placeholder="联系电话" type="text" class="layui-input" maxlength="13"
                   lay-verify="required|phone" required/>
            <input name="email" placeholder="邮箱" type="text" class="layui-input" maxlength="20"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">毕业学校</label>
        <div class="layui-input-block" style="width: 300px">
            <input name="schoolName" placeholder="毕业学校" type="text" class="layui-input" lay-verify="required"
                   required/>
            <div class="layui-form">
                <select xm-select="select13" xm-select-radio="" lay-verify="required">
                    <option value="">-学历-</option>
                    <option name="education" value="0">高中及以下</option>
                    <option name="education" value="1">大专</option>
                    <option name="education" value="2">本科</option>
                    <option name="education" value="3">研究生</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">专业技能</label>
        <div class="layui-input-block" style="width: 300px">
            <input name="skills" placeholder="专业技能" type="text" class="layui-input" lay-verify="required"
                   id="exploit-search-key"
                   required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">期望薪资</label>
        <div class="layui-input-block" style="width: 300px">
            <input name="epSalary" placeholder="期望薪资" type="text" class="layui-input" lay-verify="required"
                   required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">应聘职位</label>
        <div class="layui-input-block" style="width: 300px">
            <select name="applyPosition" xm-select="select15" xm-select-radio="">
                <option value="" id="apply_position">-应聘职位-</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item" style="padding-right: 0.5em;padding-bottom: 5ex;padding-left: 50%;
    margin:-400px 0px;float: right;">
        <label class="layui-form-label">工作经验</label>
        <div class="layui-input-block" style="width: 300px">
            <input name="workYears" placeholder="工作年限" type="text" class="layui-input" lay-verify="required"
                   required/>
        </div>
        <label class="layui-form-label">项目经历</label>
        <div class="layui-input-block" style="width: 300px">
            <textarea placeholder="项目经历" name="projectEp" id="projectEp" style="display: none;height: 500px"></textarea>
        </div>
    </div>
    <div class="layui-form-item model-form-footer" style="text-align: center">
        <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
        <button class="layui-btn" lay-filter="employee-form-submit" lay-submit>保存</button>
    </div>
</form>
</body>
</html>

<script>
    layui.use(['layer', 'admin', 'form', 'formSelects'], function () {
        var layer = layui.layer;
        var admin = layui.admin;
        var form = layui.form;
        var formSelects = layui.formSelects;
        var config = layui.config;
        var upload = layui.upload;

        form.render('radio');

        // 回显user数据
        var employee = admin.getTempData('employee');
        console.log(111111111111, employee);
        $("#id_upload_img").attr("src", employee.icon);
        // formSelects.value
        // $("#apply_position").attr("value", employee.applyPosition);
        $('#employee-form').attr('method', 'POST');
        if (employee) {
            form.val('employee-form', employee);
            $('#employee-form').attr('method', 'POST');
        }

        layui.formSelects.data('select15', 'local', {
            arr: [
                {
                    "name": "北京",
                    "value": 1,
                    "children": [
                        {
                            "name": "北京市1", "value": 12, "children": [
                                {"name": "朝阳区1", "value": 13, "children": []},
                                {"name": "朝阳区2", "value": 14, "children": []},
                                {"name": "朝阳区3", "value": 15, "children": []},
                                {"name": "朝阳区4", "value": 16, "children": []},
                            ]
                        },
                        {"name": "北京市2", "value": 17, "children": []},
                        {"name": "北京市3", "value": 18, "children": []},
                        {"name": "北京市4", "value": 19, "children": []},
                    ]
                },
                {
                    "name": "天津",
                    "value": 2,
                    "children": [
                        {"name": "天津市1", "value": 51, "children": []},
                    ]
                },
            ],
            linkage: true
        });

        //如果有需要默认值的小伙伴请使用formSelects.value
        formSelects.value($("#apply_position").attr("value", employee.applyPosition))


        // 表单提交事件
        form.on('submit(employee-form-submit)', function (data) {
            layer.load(2);
            console.log(123456789, data);
            admin.req('api-employee/empinformation/empinformation/saveOrUpdate', JSON.stringify(data.field), function (data) {
                console.log(22222222222, data);
                layer.closeAll('loading');
                if (data.code == 0) {
                    layer.msg("操作成功", {icon: 1, time: 500});
                    $(".layui-nav-img").attr("src", $("[id_upload_img=icon]").val());
                    admin.finishPopupCenter();
                } else {
                    layer.msg(data.msg, {icon: 2, time: 500});
                }
            }, $('#employee-form').attr('method'));
            return false;
        });
        layui.use('layedit', function () {
            var layedit = layui.layedit;
            layedit.build('projectEp', {
                height: 300,
                tool: ['left', 'center', 'right', '|', 'face'],
                test: 'projectEp'
            }); //建立编辑器
        });
        layui.use(['upload'], function () {
            var layer = layui.layer;
            var $ = layui.jquery, upload = layui.upload;
            //普通图片上传开始

            var uploadInst = upload.render({
                elem: '#id_upload_img',
                url: config.base_server + 'api-employee/empinformation/empinformation/picture',
                accept: 'file',
                auto: true,
                size: 1024, //限制文件大小，单位 KB
                before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#id_upload_img').attr('src', result, file.name); //图片链接（base64）
                        // $('#id_upload_img').attr('<img src="' + result + '" width="50px" height="50px" alt="' + file.name + '" class="layui-upload-img">')
                    });
                },
                done: function (data) {
                    layer.closeAll('loading');
                    console.log(data.data.url);
                    $("[id_upload_img=icon]").val(data.data.url);
                },
                error: function (data) {
                    layer.closeAll('loading');
                }
            });
            //普通图片上传结束
        })
    });
</script>